home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Java / Pdapilot-JDK-1.0 / Char4.java next >
Text File  |  1997-08-05  |  1KB  |  68 lines

  1.  
  2. package Pdapilot;
  3.  
  4. public class Char4 {
  5.     private int value;
  6.     private byte[] b;
  7.     
  8.     public Char4(int id) {
  9.         this.set(id);
  10.     }
  11.  
  12.     public Char4(String id) {
  13.         this.set(id);
  14.     }
  15.  
  16.     public Char4(byte[] b) throws java.lang.CloneNotSupportedException {
  17.         this.set(b);
  18.     }
  19.     
  20.     public Char4() {
  21.         this.set(0);
  22.     }
  23.     
  24.     public void set(int id) {
  25.         value = id;
  26.         b = new byte[4];
  27.         b[3] = (byte)(id & 0xff); id >>= 8;
  28.         b[2] = (byte)(id & 0xff); id >>= 8;
  29.         b[1] = (byte)(id & 0xff); id >>= 8;
  30.         b[0] = (byte)(id & 0xff); id >>= 8;
  31.     }
  32.  
  33.     public void set(String id) {
  34.         byte[] by = new byte[4];
  35.         id.getBytes(0, 4, by, 0);
  36.         try {
  37.             this.set(by);
  38.         } catch(java.lang.CloneNotSupportedException e) {
  39.             /* Don't be silly! */
  40.         }
  41.     }
  42.     
  43.     public void set(byte[] b) throws java.lang.CloneNotSupportedException{
  44.         this.b = (byte[])b.clone();
  45.         value = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
  46.     }
  47.     
  48.     public int getInt() {
  49.         return value;
  50.     }
  51.     
  52.     public byte[] getBytes() {
  53.         return b;
  54.     }
  55.  
  56.     public String getString() {
  57.         return new String(b, 0);
  58.     }
  59.     
  60.     public boolean equals(Char4 other) {
  61.         return (value == other.value);
  62.     }
  63.     
  64.     public String toString() {
  65.         return Util.prettyPrint(b);
  66.     }
  67. }
  68.